package com.ecelin.tools;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ecelin@ecelin.com
 */
public class CustomException extends RuntimeException {
	public CustomException(String message) {
		super(message);
		File file = new File("生成失败.txt");
		if (!file.exists()) {
			try {
				boolean newFile = file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		String pwdError = "Access denied";
		String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss: ").format(new Date());
		try {

			FileWriter fileWriter = new FileWriter(file, false);
			if (message.contains(pwdError)) {
				fileWriter.append(date).append("数据库账号或密码错误\r\n").append(message);
			} else {
				fileWriter.append(date).append(message);
			}
			fileWriter.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
